package logic

import (
	"context"
	"house/models/mysql"

	"house/houserpc/houserpc"
	"house/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookingListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookingListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookingListLogic {
	return &BookingListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BookingListLogic) BookingList(in *houserpc.BookingListRequest) (*houserpc.BookingListResponse, error) {
	// todo: add your logic here and delete this line
	var bookings []mysql.Booking
	mysql.DB.Debug().Find(&bookings)

	var BookingList []*houserpc.BookingList
	for _, booking := range bookings {
		list := houserpc.BookingList{
			UserId:  int64(booking.UserId),
			HouseId: int64(booking.HouseId),
			Name:    booking.Name,
			Mobile:  booking.Mobile,
			Address: booking.Address,
			Types:   booking.Types,
			Area:    booking.Area,
		}
		BookingList = append(BookingList, &list)
	}
	return &houserpc.BookingListResponse{
		List: BookingList,
	}, nil
}
